from django.db import models
from public.models import CommonInfo
from django.contrib.auth.models import User
from envx.models import Env
from appinput.models import App


# Create your models here.
# 该表只有三行数（CREATE,XCHANGE,DEPLOY）
class Action(CommonInfo):
    aid = models.IntegerField(unique=True, verbose_name="权限序号")


class Permission(CommonInfo):
    # 此字段关联的App应用。权限必须有App作依附，所以这行不能为空
    app_name = models.ForeignKey(App, related_name="pm_app_name", on_delete=models.CASCADE, verbose_name="App 应用")
    env_name = models.ForeignKey(Env, blank=True, null=True, related_name="pm_env_name", on_delete=models.CASCADE,
                                 verbose_name="环境")
    # 此字段关联三大类，蹦年为空
    action_name = models.ForeignKey(Action, related_name="pm_action_name", on_delete=models.CASCADE,
                                    verbose_name="操作权限")
    # 此字段为拥有上面所指定权限的用户。这时一个多对多的字段，表示这个字段里可以放置很多用户。
    main_user = models.ManyToManyField(User, blank=True, related_name="pm_user", verbose_name="操作用户")
